

package ro.ase.catalog.security.dao.hibernate;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Expression;
import ro.ase.catalog.beans.AclEntry;
import ro.ase.catalog.dao.hibernate.GenericDAOImpl;
import ro.ase.catalog.security.dao.IAclEntryDAO;

import java.util.List;

/**
 *
 */
public class AclEntryDAOImpl extends GenericDAOImpl<AclEntry, Long>  implements IAclEntryDAO {

    /* (non-Javadoc)
     * @see IAclEntryDAO#findByIdentityId(long)
     */
    @SuppressWarnings("unchecked")
    public List<AclEntry> findByIdentityId(long aclObjectIdentity) {
        DetachedCriteria criteria = DetachedCriteria.forClass(AclEntry.class);
        criteria.createCriteria("aclObject")
                .add(Expression.eq("id", aclObjectIdentity));

        return getHibernateTemplate().findByCriteria(criteria);
    }

    /* (non-Javadoc)
     * @see IAclEntryDAO#deleteByIdentityId(long)
     */
    public int deleteByIdentityId(long aclObjectId) {
        return getHibernateTemplate().bulkUpdate("delete AclEntry acl where acl.aclObject.id = ?",aclObjectId);
        
    }    
}
